/******************************************************************************
*	test.c
*
*	coypright (C) 2009 Ding Lixing
*
******************************************************************************/
#include "vm.h"
#include "cm.h"
#include "uart.h"


static cmTASK t0, t1, t2, t3, t4;
static vmSTACK s0[256], s1[256], s2[256], s3[256], s4[256];


static int testTask1(void *arg)
{
    char *tName = (char *)arg;

    for(;;){
        unsigned char ch;
        uartPrintf("%s>", tName);
        while(uartRecvByte(&ch) != 0);
        if(ch == 'i'){
            uartPrintf("hello!\r\n");
        }else if(ch == 't'){
            uartPrintf("[%s]: transfer!\r\n", tName);
            cmTaskTransfer();
        }else if(ch == 's'){
            uartPrintf("[%s]: sleep!\r\n", tName);
            cmTaskSleep(100);
            uartPrintf("[%s]: wakeup!\r\n", tName);
        }else if(ch == 'q'){
            uartPrintf("[%s]: bye!\r\n", tName);
            break;
        }else{
            uartPrintf("%s: %c\r\n", tName, ch);
        }
    }
    return 0;
}


void test1(void)
{
    uartPrintf("test 1\r\n");
    uartPrintf("\t[i]: info\r\n");
    uartPrintf("\t[t]: transfer\r\n");
    uartPrintf("\t[s]: sleep\r\n");
    uartPrintf("\t[q]: quit\r\n");
    cmTaskInit(&t0, 0, 200, (void *)s0, sizeof(vmSTACK) * 256, testTask1, (void *)"t1P0", 0);
    cmTaskInit(&t1, 0, 200, (void *)s1, sizeof(vmSTACK) * 256, testTask1, (void *)"t2P0", 0);
    cmTaskInit(&t2, 0, 200, (void *)s2, sizeof(vmSTACK) * 256, testTask1, (void *)"t3P0", 0);
    cmTaskInit(&t3, 31, 0, (void *)s3, sizeof(vmSTACK) * 256, testTask1, (void *)"t3P31", 0);
    cmTaskInit(&t4, 31, 1, (void *)s4, sizeof(vmSTACK) * 256, testTask1, (void *)"t4P31", 0);
    cmTaskStart(&t0);
    cmTaskStart(&t1);
    cmTaskStart(&t2);
    cmTaskStart(&t3);
    cmTaskStart(&t4);
}

